<template>
  <div class="dev">
    <!-- 搜索框 -->
    <div class="search">
      <el-input placeholder="请输入表号" clearable prefix-icon="el-icon-search" v-model="userName">
      </el-input>
      <el-button type="primary" icon="el-icon-search" @click="search">查找</el-button>
    </div>
    <!-- 表格数据 -->
    <div class="table">
      <el-table :data="tableData" ref="isExpand" v-loading="loading" border height="calc(100%-10rem)"
        highlight-current-row stripe style="width: 100%">
        >
        <template slot="empty">
          <el-empty description="暂无数据"></el-empty>
        </template>
        <el-table-column align="center" prop="meterNumber" label="表号">
        </el-table-column>
        <el-table-column align="center" prop="tenantName" label="租户名称">
        </el-table-column>
        <el-table-column align="center" prop="code" label="风控码">
        </el-table-column>
        <el-table-column align="center" prop="message" label="风控内容">
        </el-table-column>
        <el-table-column align="center" prop="landlordPhone" label="房东手机号">
        </el-table-column>
        <el-table-column align="center" prop="payType" label="支付类型">
          <template slot-scope="scope">
            <el-tag type="success" v-if="scope.row.payType == 1">微信</el-tag>
            <el-tag v-else>支付宝</el-tag>
          </template>
        </el-table-column>
        <el-table-column align="center" prop="createTime" label="创建时间">
        </el-table-column>
      </el-table>
      <!-- 分页 -->
      <el-pagination v-show="tableData.length !== 0" background @size-change="handleSizeChange"
        @current-change="handleCurrentChange" :current-page="pageNum" :page-sizes="[5, 10, 15, 20, 25, 30]"
        :page-size="pageSize" layout="total, sizes, prev, pager, next, jumper" :total="total">
      </el-pagination>
    </div>
  </div>
</template>

<script>
import {
  getSafeApi
} from "../../../../api/system/safe";
export default {
  data() {
    return {
      loading: false,
      tableData: [],
      pageNum: 1,
      pageSize: 10,
      total: null,
      userName:''
    };
  },
  created() {
    this.pageSize = Number(sessionStorage.getItem("pageSize")) || 10;
    this.pageNum = Number(sessionStorage.getItem("pageNum")) || 1;
    this.getSafe(this.pageNum, this.pageSize);
  },
  destroyed() {
    sessionStorage.removeItem("pageNum");
    sessionStorage.removeItem("pageSize");
  },
  methods: {
    search() {
      this.pageNum = 1
      this.getSafe(this.pageNum, this.pageSize, this.userName);
      this.$refs.isExpand.bodyWrapper.scrollTop = 0;
    },
    // 获取员工列表
    getSafe(pageNum, pageSize, userName) {
      this.loading = true;
      getSafeApi(pageNum, pageSize, userName).then((res) => {
        this.total = res.data.total;
        if (res.data.rows.length == 0) {
          this.pageNum = this.pageNum - 1;
          if (this.pageNum > 0) {
            this.search();
          } else {
            this.tableData = res.data.rows;
            this.loading = false;
          }
        } else {
          this.loading = false;
          this.tableData = res.data.rows;
        }
      });
    },
    // 分页
    handleSizeChange(val) {
      this.pageNum = 1
      this.getSafe(this.pageNum, val);
      sessionStorage.setItem("pageSize", val);
      this.pageSize = val;
      this.$refs.isExpand.bodyWrapper.scrollTop = 0;
    },
    handleCurrentChange(val) {
      this.getSafe(val, this.pageSize);
      sessionStorage.setItem("pageNum", val);
      this.pageNum = val;
      this.$refs.isExpand.bodyWrapper.scrollTop = 0;
    },
  },
};
</script>

<style lang="scss" scoped>
.dev {
  padding-top: 15px;
  padding: 0 15px;
  height: calc(100vh - 100px);

  .search {
    margin-bottom: 15px;

    .el-input {
      width: 200px;
    }

    .el-button {
      margin-left: 15px;
    }
  }

  .table {
    height: 100%;

    .el-table {
      height: 70%;
    }

    .el-pagination {
      text-align: center;
      margin-top: 20px;
    }
  }
}
</style>